package com.yssystem.controller;

import com.yssystem.domain.Do.SysDeptDO;
import com.yssystem.domain.SysDept;
import com.yssystem.domain.SysPost;
import com.yssystem.domain.vo.R;
import com.yssystem.service.SysDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/depts")
@CrossOrigin
public class DeptController {
    @Autowired
    private SysDeptService sysDeptService;
    //查询列表
    @GetMapping
    public List<SysDeptDO> getList(){
        List<SysDeptDO> list = sysDeptService.getList();
        return list;
    }
    //添加
    @PostMapping
    public R addPost(@RequestBody SysDept sysDept){
        return new R(sysDeptService.save(sysDept),"添加成功",sysDept,200);
    }

    //删除
    @DeleteMapping("/{id}")
    public R delPost(@PathVariable Integer id){
        return new R(sysDeptService.removeById(id),"删除成功",200);
    }


    //修改
    @PutMapping
    public R putPost(@RequestBody SysDept sysDept){
        return new R(sysDeptService.updateById(sysDept),"修改成功",sysDept,200);
    }

}
